import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './features/counter/counterSlice';
import pokemonReducer from './features/pokemon/pokemonSlice';
import { setupListeners } from '@reduxjs/toolkit/query';
import { pokemonApi } from '../services/pokemon';

// MARK: 1、创建 store
export const store = configureStore({
  // MARK: 3、合并所有 slice 并统一导出
  reducer: {
    counter: counterReducer,
    pokemon: pokemonReducer,
    [pokemonApi.reducerPath]: pokemonApi.reducer
  },
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(pokemonApi.middleware)
});

setupListeners(store.dispatch);

export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;
